Enforce indirect relationship Given the following structure

There's a way to enforce that Table1.id3 only can seted to values in Table4.id3 where Table4.id2 = Table1.id2?  Initially I thought in a CHECK constraint, but subqueries are not allowed.
There's a way to enforce that Table1.id3 only can seted to values in Table4.id3 where Table4.id2 = Table1.id2? 


It seems to me like you could just set a foreign key constraint directly to Table4.

alter table Table1
add constraint your_constraint_name
foreign key (id2, id3) references Table4 (id2, id3);


You might have to jump through a hoop or two to prevent a cycle in the constraints.