Bound index to number of children.

Because of imprecisions in calculating the index, it would sometimes be
out of bounds on the upper end too, so this max/min combination
constrains it between 1 and number of children.