Custom check two conditions with fields across measurements

How do you create a custom check where two fields across two measurements each meet a conditon?

Here’s an example:

import "influxdata/influxdb/schema"
import "influxdata/influxdb/monitor"

option task = {
    name: "test",
    every: 10s,
    offset: 3s,
}

cpu = from(bucket: "system")
    |> range(start: -5m)
    |> filter(fn: (r) => r["_measurement"] == "cpu")
    |> filter(fn: (r) => r["_field"] == "usage_idle")
    |> filter(fn: (r) => r["cpu"] == "cpu-total")
    |> filter(fn: (r) => r["host"] == "Anaiss-MacBook-Pro.local")
    |> last()

//   |> yield(name: "cpu")
mem = from(bucket: "system")
    |> range(start: -5m)
    |> filter(fn: (r) => r["_measurement"] == "mem")
    |> filter(fn: (r) => r["_field"] == "used_percent")
    |> filter(fn: (r) => r["host"] == "Anaiss-MacBook-Pro.local")
    |> last()

// |> yield(name: "mem")
data = union(tables: [mem, cpu])
    |> group()
    |> schema.fieldsAsCols()
    |> set(key: "_measurement", value: "cpu and mem")
// the measurement must be in the group key for the monitor.check() function
    |> group(columns: ["_measurement"], mode: "by")

//  |> yield(name: "data")
data
    |> monitor.check(
        crit: (r) => r.usage_idle < 95.0 or r.usage_percent < 50.0,
        messageFn: (r) => "test",
        data: {
            _check_name: "mycheck",
            _check_id: "0000000000000001",
            _type: "threshold",
            tags: {},
        },
    )