def filter_files_on_mdtm(remote_tstamps, local_tstamps=None):
    """
    Compare two timestamps dictionaries for files for files changed

    Filenames are basenames

    Positional arguments:
      - remote_tstamps: dict: A dictionary
          {filename: {'ftp_mdtm' : timestamp, ... }, ...}
      - local_tstamps: dict or None: A dictionary
          {filename: {'ftp_mdtm': timestamp} ... } , ...}
      If it is `None`, all files from `remote_tstamps` are returned

    Return:
      - targets_list: list: A list of filenames. Can be empty if nothing has changed.
    """
    targets_list = []
    if local_tstamps is not None:
        for f in local_tstamps:
            if local_tstamps[f]["ftp_mdtm"] != remote_tstamps[f]["ftp_mdtm"]:
                targets_list.append(f)
    else:
        targets_list = list(remote_tstamps.keys())

    return targets_list