I would recommend you use ST_HausdorffDistance() to caluclate the similarity of your GPS tracks; using
ST_Distance() will cause you issues if your tracks get near to each other at some point, but otherwise are divergent.
Hausdorff distance is a bit funny to get your head around, but it's ideal for this sort of query, and after a bit of trial and error, you can usually settle on a good value for what you consider similar.
The time part of the query can be best handled with the
INTERVAL types built in to PostgreSQL. Assuming you have one row per track, and each track has a single
TIMESTAMP representing the start time say, then queries like these work well:
SELECT TIMESTAMP '1999-12-30' - TIMESTAMP '1999-12-11' < INTERVAL '20 days';
Which returns true;
SELECT TIMESTAMP '1999-12-30' - TIMESTAMP '1999-12-11' < INTERVAL '20 minutes';
Which returns false.
So your overall query should look something like this:
SELECT a.geom FROM gps a, gps b
WHERE ST_HausdorffDistance(a.geom, b.geom) < 23.0
AND b.ts <= a.ts
AND a.ts - b.ts < INTERVAL '20 minutes';
So we're checking for the similarity of two linestrings, then only if one timestamp is less than another (to avoid two records being compared on both sides) do we see if they're temporally similar.
Caveat: I've not tried this on real data, but the syntax works on my database.