def density_filter(X, k=2, inverse=True, normalize=True, **kwargs):
    """ Return function that filters the data by codensity. 

    Parameters
    ----------
    k: int
        * calculate distance to k-th nearest neighbor

    p: float 
        * threshold percentage to keep

    Returns
    -------
    indices: tuple of np.ndarrays
        * indices of core points in the data set

    """
    from sklearn.neighbors import KDTree
    tree = KDTree(X, metric='minkowski', p=2, leaf_size=15)
    dist, ind = tree.query(X, k=k + 1)
    dens = dist[:, 1:]
    if inverse is True:
        dens = 1.0 / dens
    if normalize is True:
        dens /= dens.max(axis=0)
    return dens
