This fixes the index in cases where there's many sub items inside sub items.
When we start to go through sub menu items and their sub menu items, the depth grows by 1 level on each recursion. We also need to subtract the added level of depth when "exiting" from each sub menu item.