def wipe_distances(matrix, min_dist, max_dist):
    """
    Eliminates entries from a sparse matrix outside of a specified distance
    range.

    Parameters
    ----------
    matrix : scipy.sparse.spmatrix
        The matrix to wipe. Will be converted to COO by this function.
    min_dist, max_dist : int
        The minimum and maximum distance allowed, respectively, in bin units.

    Returns
    -------
    scipy.sparse.coo_matrix
        The wiped matrix.
    """
    coo = matrix.tocoo()
    dist = coo.col - coo.row
    coo.data[(dist < min_dist) | (dist > max_dist)] = 0
    coo.eliminate_zeros()
    return coo