def is_allowed(pair, index_a_max, index_b_max):
    """
    A pair of cell indices is only allowed
    if it is still on the grid.
    """
    allowed = False
    if pair[0] >= 0 and pair[0] < index_a_max:
        if pair[1] >= 0 and pair[1] < index_b_max:
            allowed = True
    return allowed