<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def save_matches(self, matches):
 """Save matches of a failed execution to the log. :param matches: a list of matches in JSON format """

        if not os.path.exists(os.path.dirname(self.location())):
            os.makedirs(os.path.dirname(self.location()))

        with open(self.location(), "w+") as f:
            matches = [m for m in matches if not m['processed']]
            for m in matches:
                match_obj = json.dumps(m)
                f.write(match_obj + "\n")