def filter_by_db_refs(stmts_in, namespace, values, policy, **kwargs):
    invert = kwargs.get('invert', False)
    match_suffix = kwargs.get('match_suffix', False)
    if policy not in ('one', 'all'):
        logger.error('Policy %s is invalid, not applying filter.' % policy)
        return
    else:
        name_str = ', '.join(values)
        rev_mod = 'not ' if invert else ''
        logger.info(('Filtering %d statements for those with %s agents %s'
                     'grounded to: %s in the %s namespace...') %
                        (len(stmts_in), policy, rev_mod, name_str, namespace))
    def meets_criterion(agent):
        if namespace not in agent.db_refs:
            return False
        entry = agent.db_refs[namespace]
        if isinstance(entry, list):
            entry = entry[0][0]
        ret = False
        if match_suffix:
            if any([entry.endswith(e) for e in values]):
                ret = True
        else:
            if entry in values:
                ret = True
        if invert:
            return not ret
        else:
            return ret
    enough = all if policy == 'all' else any
    stmts_out = [s for s in stmts_in
                 if enough([meets_criterion(ag) for ag in s.agent_list()
                            if ag is not None])]
    logger.info('%d Statements after filter...' % len(stmts_out))
    dump_pkl = kwargs.get('save')
    if dump_pkl:
        dump_statements(stmts_out, dump_pkl)
    return stmts_out