<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_words(words, filters_in=None, filters_out=None, flags=0):
 """ Filters the words using the given filters. Usage:: [u'John', u'Doe', u'Doe'] [u'Users', u'are'] [u'Users', u'are', u'Jane', u'Z6PO'] :param filters_in: Regex filters in list. :type filters_in: tuple or list :param filters_in: Regex filters out list. :type filters_in: tuple or list :param flags: Regex flags. :type flags: int :return: Filtered words. :rtype: list """


    filtered_words = []
    for word in words:
        if filters_in:
            filter_matched = False
            for filter in filters_in:
                if not re.search(filter, word, flags):
                    LOGGER.debug("> '{0}' word skipped, filter in '{1}' not matched!".format(word, filter))
                else:
                    filter_matched = True
                    break
            if not filter_matched:
                continue

        if filters_out:
            filter_matched = False
            for filter in filters_out:
                if re.search(filter, word, flags):
                    LOGGER.debug("> '{0}' word skipped, filter out '{1}' matched!".format(word, filter))
                    filter_matched = True
                    break
            if filter_matched:
                continue
        filtered_words.append(word)
    LOGGER.debug("> Filtered words: '{0}'".format(", ".join(filtered_words)))
    return filtered_words