def filter_stubs(tracks, threshold=100):
    """Filter out trajectories with few points. They are often spurious.

    Parameters
    ----------
    tracks : DataFrame
        must include columns named 'frame' and 'particle'
    threshold : integer, default 100
        minimum number of points (video frames) to survive

    Returns
    -------
    a subset of tracks
    """
    try:
        tracks['frame']
        tracks['particle']
    except KeyError:
        raise ValueError("Tracks must contain columns 'frame' and 'particle'.")
    grouped = tracks.reset_index(drop=True).groupby('particle')
    filtered = grouped.filter(lambda x: x.frame.count() >= threshold)
    return filtered.set_index('frame', drop=False)