helper function for filtering dicts