hist: factor out bin index range selection