The permission on "own content" is connected to the node's author's uid and only relates to role in that a user with the role holding that permission can edit a node they created.
How I would solve your use case is with a hook_node_access in a custom module.
https://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_access/7
WARNING: I just threw this together as an example, I did not test, and you need to put in the right role values.
hook_node_access($node, $op, $account) {
if( $op !== 'update'){
// not my use-case
return NODE_ACCESS_IGNORE;
}
$author = user_load($node->uid);
if( in_array( 'role1', $author->roles) && in_array( 'role1', $account->roles) ) {
// the user editing has the same role as the author
return NODE_ACCESS_ALLOW;
}
// repeat ... etc.
// we did not find what we were looking for, continue with normal access check
return NODE_ACCESS_IGNORE;
}