def filter_packages_by_licenses(packages_metadata, licenses):
    """
    Returned a filtered dictionary of packages that matches the licenses.
    """
    matching_packages = {}
    for package, pkg_data in packages_metadata.items():
        if pkg_data.license in licenses:
            matching_packages[package] = pkg_data
    return matching_packages
