Fix inferred latch in one_hot_to_index
Make integer loop counters local everywhere.