Querying on multiple joined rows
It's a case of relational-division.
We have assembled an arsenal of query techniques in this related answer on SO:


How to filter SQL results in a has-many-through relation


For your case this query will be among the fastest possible solutions:

SELECT v.*
FROM   params p1
JOIN   params p3 USING (visit_id)
JOIN   visits v  ON v.id = p3.visit_id
WHERE  p1.a_key = 'key1' AND p1.a_value = 'value1'
AND    p3.a_key = 'key3' AND p3.a_value = 'value3';


If you just need the visit_id you don't even need to join to table visits.

db&lt;>fiddle here
Old sqlfiddle.