Check that index is within range