Write a function to detect anomalies in user transaction histories at Tink.
Implement detect_anomalies(transactions). Each transaction is a dictionary with string fields id and user_id, and a numeric amount. Process transactions in order. After a user has at least three previous transactions, mark the current transaction as anomalous when its amount is at least three times that user's previous average amount. Return anomalous transaction IDs in input order. Do not use the current transaction when calculating its baseline.
Input: a list of transaction dictionaries. Output: a list of strings. Amounts are non-negative.
def detect_anomalies(transactions):