Indirect constraints (foreign keys amongst three/four tables)
Your business rules will dictate your schema modeling. It is important you establish all these rules first. 
If a user can belong to multiple Group (group 1 , group 2, group3) than it is the rule. If you don't want a user to be able to be inserted in a group that belongs to another company, you need to program this logic at the application layer. FK itself only checks the key exists in parent on insertion. (it does not verify for you if that user is from group 1 or 2). If you want to enforce this, i would recommend using triggers and using a userGroup table:

USER ------------(n:1)------------ COMPANY
USER ---(n:m)--- UserGROUP --(n:m)---- Group---(m:1)--- COMPANY

UserGROUP (group_id,user_id, roleId) 
(PK on group_id, userId to enforce 1 user role per group) 

Trigger On insert in UserGROUP:
 if user.company_id = group_company_id, then insert else "error".