def filter_data(df, motion_thresh, age_l, age_u, motion_measure='func_perc_fd'):
    """
    This function filters the data so you're looking at data
    within a certain age range (between age_l and age_u *inclusive*)
    and with particpants who have motion lower than a certain
    value of motion_measure (set to func_perc_fd by default but
    an alternative value would be func_mean_fd.
    """
    # Start by removing all participants whose data is below a certain
    # motion threshold.
    df_samp_motion =  df.loc[df[motion_measure] < motion_thresh, :]

    # Then remove participants who are younger (in years) than age_l and older
    # than age_u. Note that this means people who are age_l and age_u
    # (eg 6 and 10) will be included in the sample.
    df_samp = df_samp_motion.loc[(df_samp_motion['AGE_YRS']>=age_l)
                                  & (df_samp_motion['AGE_YRS']<=age_u), :]

    return df_samp