I have used much the same code. But have put it in its own template/module and then included it in tpl_index_categories.php.
The reason for that is that most people seem to want to keep the subcategory links as well, which I think might get lost in the method DrByte mentioned. So, putting it all in its own file allows it to be slotted in wherever people want.
Bookmarks