Implement an algorithmic solution to identify anomalies within a sliding time-window stream.
Given time-ordered events (timestamp, value), return the zero-based indices whose values are anomalous compared with prior events inside the time window. Use the population standard deviation and classify an event when its absolute z-score is greater than threshold after at least min_history prior events exist. If the standard deviation is zero, any different value is anomalous. Implement detect_anomalies(events, window, threshold, min_history) and return a list of indices.
def detect_anomalies(events, window, threshold, min_history):