<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def filter_metadata(metadata, user_filter, default_filter):
 """Filter the cell or notebook metadata, according to the user preference"""

    actual_keys = set(metadata.keys())
    keep_keys = apply_metadata_filters(user_filter, default_filter, actual_keys)

    for key in actual_keys:
        if key not in keep_keys:
            metadata.pop(key)

    return metadata